<template>
	<view>
		<view class="search">
			<view class="search-item" @click="dateShow = true">
				<u-search placeholder="选择日期筛选"
					shape="square"
					:disabled="true"
					v-model="searchValue"
					:showAction="false"
					@change="searchChange">
				</u-search>
			</view>
			<view class="add-button" @click="searchValue = ''">
				重置
			</view>
		</view>
		<view style="margin-top: 100rpx;" v-if="list.length < 1">
			<u-empty
				text="暂无数据"
				icon="https://www.zxsl.zxmap.cn/zxch-app/2023/07/21/005b6980c9514d1e8e4a0cee0de018e4.png">
			</u-empty>
		</view>
		
		<view>
			<u-swipe-action>
				<u-swipe-action-item
					:disabled="true"
					:options="options" 
					v-for="(item,index) in list" :key="item.id">
					<view class="swipe-action u-border-top u-border-bottom" @click="gotoPage('/subPackTask/work/cy/bywx/detail?id='+item.id)">
						<view class="PhotographerBoxL">
							<view class="cu-avatar round xl" :style="'background-image:url('+item.frontImage+')'">
							</view>
							<view class='cu-tag2 margin-top-xs bg-blue radius'>{{item.carNum}}</view>
						</view>
						<view class="PhotographerBoxR">
							<view class="text-sm text-bold">维保日期：{{item.time}}</view>
							<view class="text-sm text-grey margin-top-xs">类型：{{item.type}}</view>
							<view class="text-sm text-grey margin-top-xs">维保人：{{item.userName}}</view>
						</view>
					</view>
				</u-swipe-action-item>
			</u-swipe-action>
		</view>
		
		<u-calendar
			:show="dateShow"
			:maxDate="String(new Date())"
			:minDate="minDate"
			monthNum="7"
			:closeOnClickOverlay="true"
			@close="dateShow = false"
			@confirm="dateConfirm">
		</u-calendar>
		
		<uni-fab
			:content="content"
			horizontal="right"
			vertical="bottom"
			direction="vertical"
			@trigger="trigger">
		</uni-fab>
	</view>
</template>

<script>
	import { getList } from '@/api/maintenance.js'
	export default {
		data() {
			return {
				options:[{}],
				minDate:new Date() - 6*30*24*60*60*1000,
				dateShow:false,
				searchValue:'',
				list:[],
				pageNum:1,
				content: [{
						path:'/subPackTask/work/cy/bywx/add',
						iconPath: 'https://www.zxsl.zxmap.cn/zxch-app/2023/07/21/23a847a2b8e84bf7809ce2b8d710ab4d.png',
						selectedIconPath: 'https://www.zxsl.zxmap.cn/zxch-app/2023/07/21/23a847a2b8e84bf7809ce2b8d710ab4d.png',
						text: '添加维保',
						active: false
					},
				],
			}
		},
		onShow() {
			this.pageNum = 1
			this.list = []
			this.getWbList()
		},
		onReachBottom(){
			this.pageNum += 1
			this.getWbList()
		},
		onPullDownRefresh(){
			this.pageNum = 1
			this.list = []
			this.getWbList()
			uni.stopPullDownRefresh()
		},
		methods: {
			async getWbList(){
				let params = {
					time:this.searchValue,
					pageNum:this.pageNum,
				}
				const { data } = await getList(params);
				if(data.code == 200 && data.rows.length > 0){
					this.list = [...this.list,...data.rows]
				}
			},
			searchChange(value){
				this.pageNum = 1
				this.list = []
				this.getWbList()
			},
			dateConfirm(value){
				this.searchValue = value[0]
				this.dateShow = false
			},
			trigger(e){
				this.gotoPage(e.item.path)
			},
		}
	}
</script>

<style>
	page{
		background-color: #f6f6f6;
		color: #333333;
	}
	
	.add-button{
		line-height: 104rpx;
		color: #0081ff;
	}
</style>